/*
 *  nautilus-svn-prompt.c - Subversion extension for Nautilus
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Author: Jack Xu Hong <jack.xu.hong@gmail.com>
 *
 */

#include <config.h>

#include <gtk/gtk.h>
#include <glade/glade.h>

#include <svn_client.h>
#include <svn_cmdline.h>

#include "nautilus-svn.h"
#include "nautilus-svn-prompt.h"


static void
destroy_cb (GtkWidget         *widget,
            NautilusSvnPrompt *prompt)
{
	g_free (prompt);
}

NautilusSvnPrompt *
nautilus_svn_prompt_new (GtkWidget   *parent)
{
	NautilusSvnPrompt *prompt;
	GladeXML *xml;

	prompt = g_new0 (NautilusSvnPrompt, 1);

	xml = glade_xml_new (GLADEDIR "/nautilus-svn-prompt.glade",
	                     NULL, NULL);

	prompt->window = glade_xml_get_widget (xml, "dialog_prompt");
	g_signal_connect (prompt->window,
	                  "destroy",
	                  G_CALLBACK (destroy_cb),
	                  prompt);

	prompt->entry_realm = glade_xml_get_widget(xml, "entry_realm");
	prompt->entry_username = glade_xml_get_widget(xml, "entry_username");
	prompt->entry_password = glade_xml_get_widget(xml, "entry_password");

	g_object_unref(xml);

	if (GTK_IS_WIDGET(parent))
		gtk_widget_set_parent(prompt->window, parent);

	return prompt;
}


gint
nautilus_svn_prompt_run (NautilusSvnPrompt *prompt,
                         const gchar *realm,
                         const gchar *username)
{
	if (realm)
		gtk_entry_set_text (GTK_ENTRY (prompt->entry_realm), realm);

	if (username)
		gtk_entry_set_text (GTK_ENTRY (prompt->entry_username), username);

	return gtk_dialog_run (GTK_DIALOG (prompt->window));
}

const gchar *
nautilus_svn_prompt_get_username (NautilusSvnPrompt *prompt)
{
	return gtk_entry_get_text (GTK_ENTRY (prompt->entry_username));
}

const gchar *
nautilus_svn_prompt_get_password (NautilusSvnPrompt *prompt)
{
	return gtk_entry_get_text (GTK_ENTRY (prompt->entry_password));
}
